local BehaveMgr  = class("BehaveMgr");
function BehaveMgr:ctor()
	self.behaveList = {};
	self.dic = {};
	local groups = {
        {enums.Behave.Hint},
        {enums.Behave.Bulletin},
        {enums.Behave.TopFighterRefresh},
        {enums.Behave.RecruitSailor},
        {enums.Behave.VersionUpdateWnd,enums.Behave.AppraiseWnd,enums.Behave.RandomEventWnd,enums.Behave.FuncOpenWnd}
    };
	for i,v in ipairs(groups)  do
		if type(v) == "table" then
			self.behaveList[i] = {};
			for j,value in ipairs(v)  do
				if self.dic[value] ~= nil then
					assert(value .. " behave id duplicate");
				end
				self.dic[value] = i;
			end
		else
			assert("BehaveMgr groups error");
		end
	end
end
function BehaveMgr:getGroupArr(behaveId)
	if self.dic[behaveId] == nil then
		assert("behaveId not found");
	end
	return self.behaveList[self.dic[behaveId]];
end


function BehaveMgr:addBehave(func, behaveId)
	if DEBUG then
		assert(behaveId ~= nil,"behaveId error!");
	else
		return;
	end
	
	local t = self:getGroupArr(behaveId);
	table.insert(t,func);
end
function BehaveMgr:nextBehave(behaveId,s)
	local t = self:getGroupArr(behaveId);
	if table.maxn(t) == 0 then
		return;
	end
	
	if s == nil then
		s = 0;
	end
	local func = t[1];
	table.remove(t,1);
	if s <= 0 then
		func();
	else
		mgrs.scheduler:performWithDelayGlobal(func,s);
	end
end

mgrs.behave = nil;
mgrs.singleClass(mgrs,BehaveMgr,"behave");
